import Vue from 'vue'
import Router from 'vue-router'
import store from '../store/store'

Vue.use(Router)

const router = new Router({
    mode: 'history',
    routes: [
        // {name: 'login', path: '/', component: () => import('@/views/Login.vue')},
        {
            name: 'home', path: '/', meta: {role: ['USER', 'ADMIN']}, component:() => import('@/views/Home.vue'), children: [
                {name: 'user', path: '/user', component:() => import('@/views/User.vue')},
                {name: 'hello', path: '/hello', meta: {role: ['USER']}, component:() => import('@/views/Hello.vue')},
                {name: 'me', path: '/me', meta: {role: ['USER']}, component: () => import('@/views/Me.vue')},
                {name: 'handover', path: '/handover', meta: {role: ['USER']}, component:() => import('@/views/Handover.vue')}]
        },
    ]
})

// router.beforeEach((to, from, next) => {
//     if (to.name === 'login' || !to.meta.role || to.meta.role.includes(store.state.user.role)) {
//         next()
//     }
//     else {
//         next({name: 'login', params: {to: to.name}})
//     }
// })

export default router